package cn.javadog.ssp.spring.ioc.circle;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 余勇
 * @date 2019年11月27日 13:25:00
 */
@Configuration
public class CircleBeanConfig {


	@Bean
	public CircleBeanA getCircleBeanA(){
		return new CircleBeanA();
	}

	@Bean
	public CircleBeanB getCircleBeanB(CircleBeanA circleBeanA){
		return new CircleBeanB(circleBeanA);
	}


	/**
	 * 测试循环依赖
	 */
	static class CircleBeanA {
		@Autowired
		private CircleBeanB circleBeanB;

		public CircleBeanA() {
			System.out.println("CircleBeanA初始化, circleBeanB是否为空呢？ " +  circleBeanB);
		}

	}

	static class CircleBeanB {
		private CircleBeanA circleBeanA;

		public CircleBeanB(CircleBeanA circleBeanA){
			System.out.println("CircleBeanB初始化，circleBeanA是否为空呢？ " +  circleBeanA);
			this.circleBeanA = circleBeanA;
		}
	}


}
